const inquirer = require('inquirer')
const fs = require('fs')
inquirer
    .prompt([
        {
            type: 'list',
            name: 'brand',
            message: '汽车品牌',
            choices: ['自行输入', '日产', '本田', '大众', '奔腾', '传祺'],
            // default: '太平洋汽车',
            filter: function (val) { return val != '自行输入' && (val + '汽车') }
        },
        {
            type: 'input',
            name: 'brand2',
            message: '输入品牌',
            when: answers => !answers.brand,
            default: '太平洋汽车',
        },
        {
            type: 'input',
            name: 'title',
            message: '专题的标题',
            default: '太平洋汽车',
        },
        {
            type: 'input',
            name: 'author',
            message: '开发的名字（如：zhangsan_gz）',
            default: 'none',
        },
        {
            type: 'input',
            name: 'designer',
            message: '设计的名字（如：lisi_bj）',
            default: 'none',
        }
    ])
    .then(answers => {
        answers.brand2 && (answers.brand = answers.brand2);

        let oStr='module.exports ='+JSON.stringify(answers) 
        //把此对象写入hdata.js,  路径根据package.json
        fs.writeFileSync('./src/template/components/data/hdata.js', oStr, function (err) {
            if (err) console.log('写入hdata.js失败', err);
            else console.log('写入hdata.js成功！');
        })
        console.log(answers.brand, answers.title, answers.author, answers.designer)
        console.log(answers)
    })
